package org.aphasia4j.dao.impl;

import java.util.Collections;
import java.util.List;

import org.aphasia4j.dao.WordDao;
import org.aphasia4j.dao.core.BaseDaoSupport;
import org.aphasia4j.model.Category;
import org.aphasia4j.model.Word;

/**
 * Implementation of the {@link WordDao} interface description.
 * 
 * @author hillger.t
 */
public class WordDaoImpl extends BaseDaoSupport<Word> implements WordDao {

  @SuppressWarnings("unchecked")
  public List<Word> getWords(int count) {
    String jql = "select w from Word w";
    List<Word> res = getJpaTemplate().find(jql);
    Collections.shuffle(res);
    return res.subList(0, count);
  }

  @SuppressWarnings("unchecked")
  public List<Word> getWordsByCatory(int count, Category category) {
    String jql = "select w from Word w where ? in (w.categories)";
    List<Word> res = getJpaTemplate().find(jql, category);
    Collections.shuffle(res);
    return res.subList(0, count);
  }
}
